local fangzhu = fk.CreateSkill{
  name = "sj4__fangzhu",
}

Fk:loadTranslationTable{
  ["sj4__fangzhu"] = "放逐",
  [":sj4__fangzhu"] = "所有角色均行动过的轮次结束或你受到1点伤害后，你可令一名角色依次执行至无法执行：1.视为使用一张【火攻】；2.横置；3.横置。其每执行一项后便翻面。",

  ["#sj4__fangzhu-choose"] = "放逐：你可以令一名角色依次执行至无法执行：1.视为使用一张【火攻】；2.横置；3.横置。其每执行一项后便翻面",

  ["$sj4__fangzhu1"] = "远步踏青草，独吊旧人坟。",
  ["$sj4__fangzhu2"] = "且行莫回顾，至处感吾恩。",
}

local fangzhu_spec = {
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = room:askToChoosePlayers(player, {
      targets = room.alive_players,
      min_num = 1,
      max_num = 1,
      prompt = "#sj4__fangzhu-choose",
      skill_name = fangzhu.name,
      cancelable = true,
    })
    if #to > 0 then
      event:setCostData(self, {tos = to})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local to = event:getCostData(self).tos[1]
    local room = player.room
    if room:askToUseVirtualCard(to,{
      name = "fire_attack",
      skill_name = fangzhu.name,
      cancelable = false,
     }) and not to.dead then
      to:turnOver()
      for _ = 1, 2, 1 do
        if to.chained or to.dead then 
          break
        else
          to:setChainState(true)
          if to.chained and not to.dead then --对无法横置的兼容
            to:turnOver()
          else
            break
          end
        end
      end
    end
  end,
}

fangzhu:addEffect(fk.Damaged, {
  anim_type = "masochism",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(fangzhu.name) and player == target
  end,
  trigger_times = function(self, event, target, player, data)
    return data.damage
  end,
  on_cost = fangzhu_spec.on_cost,
  on_use = fangzhu_spec.on_use,
})

fangzhu:addEffect(fk.RoundEnd, {
  anim_type = "masochism",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(fangzhu.name) then
      local room = player.room
      local ps = {}
      return #room.logic:getEventsOfScope(GameEvent.Turn,1,function (e)
        table.insertIfNeed(ps,e.data.who.id)
        return #ps == #room.alive_players
      end,Player.HistoryRound) > 0
    end
  end,
  on_cost = fangzhu_spec.on_cost,
  on_use = fangzhu_spec.on_use,
})

return fangzhu